package pl.edu.pk.mech.kkbus.entities;

import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.OneToMany;
import javax.persistence.CascadeType;

import com.google.appengine.api.datastore.Key;
import org.springframework.security.core.GrantedAuthority;

@Entity
public class User {

    public enum Role implements GrantedAuthority {
        ADMIN (0),
        USER (1),
        WORKER(2);

        private int bit;

        Role(int bit) {
            this.bit = bit;
        }

        @Override
        public String getAuthority() {
            return toString();
        }
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;
    private String name;
    private String surname;
    @Temporal(TemporalType.TIMESTAMP)
    private Date birthday;
    private String email;
    private String phone;
    private boolean enabled;
    private String password;
    private String hash;
    private int points;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private List<HistoryLog> historyLogs;
    private Set<Role> roles;

    public User() {
    }

    public Key getKey() {
        return key;
    }

    public void setKey(Key key) {
        this.key = key;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getHash() {
        return hash;
    }

    public void setHash(String hash) {
        this.hash = hash;
    }

    public int getPoints() {
        return points;
    }

    public void setPoints(int points) {
        this.points = points;
    }

    public List<HistoryLog> getHistoryLogs() {
        return historyLogs;
    }

    public void setHistoryLogs(List<HistoryLog> historyLogs) {
        this.historyLogs = historyLogs;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }
   
}